﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.loading.pipes {
    import net.wooga.pets.loading.vos.*;
    import __AS3__.vec.*;
    import net.wooga.pets.loading.interfaces.*;

    public class LoaderPipe {

        private var _waitingQueue:Vector.<IRequestLoader>;
        private var _isBusy:Boolean;// = false

        public function LoaderPipe(){
            this._waitingQueue = new Vector.<IRequestLoader>();
            super();
        }
        public function addLoader(_arg1:IRequestLoader):void{
            if (this._isBusy){
                this.addToPipe(_arg1);
            } else {
                this.startLoader(_arg1);
            };
        }
        private function addToPipe(_arg1:IRequestLoader):void{
            if (this._waitingQueue.indexOf(_arg1) == -1){
                this._waitingQueue.push(_arg1);
            };
        }
        private function handleLoaded(_arg1:String, _arg2:ResultVO):void{
            var _local3:IRequestLoader;
            this._isBusy = false;
            if (this._waitingQueue.length){
                _local3 = this._waitingQueue.shift();
                this.startLoader(_local3);
            };
        }
        private function startLoader(_arg1:IRequestLoader):void{
            this._isBusy = true;
            _arg1.loaded.addOnce(this.handleLoaded);
            _arg1.start();
        }

    }
}//package net.wooga.pets.loading.pipes 
